package cn.icanci.loopstack.ddk.client.repository;

import java.lang.reflect.Method;
import java.util.Objects;
import java.util.StringJoiner;

/**
 * @author icanci
 * @since 1.0 Created in 2023/01/13 23:45
 */
public class MethodHolder {
    /**
     * 资源名称
     */
    private String   resource;
    /**
     * 资源上次刷新值
     */
    private String   value;
    /**
     * 资源对应的方法，使用 @DdkBeforeCall 标记的方法
     * 其中需要传参数，值为String类型
     */
    private Method   beforeMethodCall;
    /**
     * 资源对应的方法，使用 @DdkCall 标记的方法
     * 其中需要传参数，值为String类型
     */
    private Method   methodCall;
    /**
     * 资源对应的方法，使用 @DdkAfterCall 标记的方法
     * 其中需要传参数，值为String类型
     */
    private Method   afterMethodCall;
    /**
     * 资源对应的类
     */
    private Class<?> clazz;
    /**
     * 资源对应的SpringBean对象
     */
    private Object   bean;

    public String getResource() {
        return resource;
    }

    public void setResource(String resource) {
        this.resource = resource;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Method getBeforeMethodCall() {
        return beforeMethodCall;
    }

    public void setBeforeMethodCall(Method beforeMethodCall) {
        this.beforeMethodCall = beforeMethodCall;
    }

    public Method getMethodCall() {
        return methodCall;
    }

    public void setMethodCall(Method methodCall) {
        this.methodCall = methodCall;
    }

    public Method getAfterMethodCall() {
        return afterMethodCall;
    }

    public void setAfterMethodCall(Method afterMethodCall) {
        this.afterMethodCall = afterMethodCall;
    }

    public Class<?> getClazz() {
        return clazz;
    }

    public void setClazz(Class<?> clazz) {
        this.clazz = clazz;
    }

    public Object getBean() {
        return bean;
    }

    public void setBean(Object bean) {
        this.bean = bean;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        MethodHolder that = (MethodHolder) o;
        return Objects.equals(resource, that.resource) && Objects.equals(value, that.value) && Objects.equals(beforeMethodCall, that.beforeMethodCall)
               && Objects.equals(methodCall, that.methodCall) && Objects.equals(afterMethodCall, that.afterMethodCall) && Objects.equals(clazz, that.clazz)
               && Objects.equals(bean, that.bean);
    }

    @Override
    public int hashCode() {
        return Objects.hash(resource, value, beforeMethodCall, methodCall, afterMethodCall, clazz, bean);
    }

    @Override
    public String toString() {
        return new StringJoiner(",").add("resource=" + resource).add("value=" + value).add("beforeMethodCall=" + beforeMethodCall).add("methodCall=" + methodCall)
            .add("afterMethodCall=" + afterMethodCall).add("clazz=" + clazz).add("bean=" + bean).toString();
    }
}
